/*
 * Written by Anders Fongen
 * Norwegian Defence Research Establishment (FFI)
 * Email: anders@fongen.no
 */

package no.ffi.gismoidm.certstore;

import java.security.cert.X509Certificate;
import no.ffi.fca.certstore.DatabaseStorageService;
import no.ffi.gismoidm.utils.GismoIdmException;

/**
 * @author anf
 * Created on 28.jun.2008
 */
public class CertificateServiceFactory {
    public static final String HASHNAMES = "HASHNAMES";
    public static final String WEBCA = "WEBCA";
    public static final String DBSTORE = "DBSTORE";
    
    private static CertificateService hashfile = null;
    private static CertificateService webstore = null;
    private static CertificateService dbstore = null;
    
    public static CertificateService getInstance(String parameter,X509Certificate trustAnchor) throws Exception {
        if (parameter.equals(HASHNAMES))  {
            if (hashfile==null)  {
                hashfile = new HashnameStorageService(trustAnchor);
                System.out.println("HASHNAME allokert");
            }
            return hashfile;
        }
        if (parameter.equals(WEBCA))  {
            if (webstore==null)  {
                webstore = new WebStorageService(trustAnchor);
                System.out.println("WEBCA allokert");
            }
            return webstore;
        }
        if (parameter.equals(DBSTORE))  {
            if (dbstore==null)  {
                dbstore = new DatabaseStorageService(trustAnchor);
                System.out.println("DBSTORE allokert");
            }
            return dbstore;
        }
        throw new GismoIdmException("Illegal parameter value for CertificateServiceFactory: " + parameter + ".");
    }
}
